package com.project.service;

import com.project.dao.OrgInfoMapper;
import com.project.entity.OrgInfo;
import com.project.service.base.BaseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by WheelChen on 2017/4/25.
 */
@Transactional(rollbackFor=Exception.class)
@Service
public class OrgInfoServiceImpl extends BaseService implements OrgInfoService{
    private static OrgInfoMapper orgInfoMapper = null;
    public void setMapper()
    {
        if(orgInfoMapper==null)
            orgInfoMapper = sqlSessionTemplate.getMapper(OrgInfoMapper.class);//1.获取相关mapper
    }

    @Override
    public int addOrgInfo(OrgInfo orgInfo) {
        setMapper();
        return orgInfoMapper.insertSelective(orgInfo);
    }

    /**
     * author: WheelChen
     * date: 2017/6/26
     * function: 通过id查找公司信息
     *
     * @param id
     * @return
     */
    @Override
    public OrgInfo findByid(Integer id) {
        setMapper();
        return orgInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public int modifyByManagerId(OrgInfo orgInfo) {
        setMapper();
        return orgInfoMapper.updateByManageIdSelective(orgInfo);
    }

    /**
     * author: WheelChen
     * date: 2017-5-22
     * function: 根据managerid修改公司信息
     *
     * @param orgInfo
     * @return
     */
    @Override
    public int modifyByCreatorId(OrgInfo orgInfo) {
        setMapper();
        return orgInfoMapper.updateBymodifyByCreatorIdSelective(orgInfo);
    }

    @Override
    public List<OrgInfo> findOrgInfoBatch() {
        setMapper();
        return orgInfoMapper.selectAll();
    }

    @Override
    public List<OrgInfo> findByCondition(OrgInfo orgInfo) {
        setMapper();
        return orgInfoMapper.selectByCondition(orgInfo);
    }

    @Override
    public OrgInfo findByManagerId(Integer managerid) {
        setMapper();
        return orgInfoMapper.selectByManagerId(managerid);
    }

    /**
     * author: WheelChen
     * date: 2017/6/26
     * function: 根据id修改
     *
     * @param orgInfo
     * @return
     */
    @Override
    public int modifyById(OrgInfo orgInfo) {
        setMapper();
        return orgInfoMapper.updateByPrimaryKeySelective(orgInfo);
    }

    /**
     * author: WheelChen
     * date: 2017/7/31
     * function: 查询所有公司信息
     *
     * @return
     */
    @Override
    public List<OrgInfo> findAll() {
        setMapper();
        return orgInfoMapper.selectAll();
    }
}
